package com.example.juc;

import lombok.extern.slf4j.Slf4j;

/**
 * @Description
 * @Date 2021/7/25
 * @Created by Jonathan
 */
@Slf4j
public class MyDemo {

    private static ThreadLocal<String> tl = new ThreadLocal<>();

    private String content;

    private String getContent() {
        return tl.get();
    }

    private void setContent(String content) {
        tl.set(content);
    }

    public static void main(String[] args) {
        MyDemo demo = new MyDemo();
        for (int i = 0; i < 5; i++) {
            Thread thread = new Thread(() -> {
                demo.setContent(Thread.currentThread().getName() + "的数据");
                log.info("-----------------------");
                log.info(Thread.currentThread().getName() + "--->" + demo.getContent());
            }, "线程" + i);
            thread.start();
        }
    }
}
